import { extend } from "vue/types/umd";

/**
 * 接口
 */
interface Config {
  type: string;
  url: string;
  data?: string;
  dataType: string;
}

function ajax(config: Config) {
  let xhr = new XMLHttpRequest();
  xhr.open("get", config.url, true);
  xhr.send(config.data);

  xhr.onreadystatechange = function () {
    if (xhr.readyState == 4 && xhr.status == 200) {
      console.log("成功");
      let result;
      if (config.dataType == "json") {
        result = JSON.parse(xhr.responseText);
      } else {
        result = xhr.responseText;
      }
      console.log(result);
    }
  };
}

//函数类型接口
interface Encrypt {
  (key: string, value: string): string;
}

let md5: Encrypt = (key, value) => {
  return "md5";
};
md5("first", "second");

let sha1: Encrypt = (key, value) => {
  return "sha1";
};

//类类型接口
interface Animal {
  name: string;
  eat(food: string): void;
}

class Cat implements Animal {
  name: string;
  constructor(name: string) {
    this.name = name;
  }
  eat(food: string): void {
    throw new Error("Method not implemented.");
  }
}
//接口继承
interface Person extends Animal {
  work(): void;
}

class Web implements Person {
  work(): void {
    throw new Error("Method not implemented.");
  }
  name: string;
  constructor(name: string) {
    this.name = name;
  }
  eat(food: string): void {
    throw new Error("Method not implemented.");
  }
}
class Engier extends Web implements Person {
  constructor(name: string) {
    super(name);
  }
  study(flag: string): void {
    console.log(flag);
  }
}
let nav1 = new Engier("Ren");
